package com.oywy.rbac.controller;

import com.oywy.rbac.entity.Authority;
import com.oywy.rbac.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

/**
 * 权限管理控制器
 *
 * @author oywy
 * @date 2018/10/22
 */
@RestController
@RequestMapping("authority")
public class AuthorityController {
    @Autowired
    private AuthorityService authorityService;

    @GetMapping
    @PreAuthorize("hasAuthority('list_authority')")
    public Collection<Authority> list() {
        return authorityService.list();
    }

    @GetMapping("{id}")
    @PreAuthorize("hasAuthority('get_authority')")
    public Authority get(@PathVariable String id) {
        return authorityService.get(id);
    }

    @PostMapping
    @PreAuthorize("hasAuthority('post_authority')")
    public Authority post(Authority authority) {
        return authorityService.post(authority);
    }

    @PutMapping
    @PreAuthorize("hasAuthority('put_authority')")
    public Authority put(Authority authority) {
        return authorityService.put(authority);
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasAuthority('del_authority')")
    public void delete(@PathVariable String id) {
        authorityService.del(id);
    }
}
